import 'dart:convert';

import 'package:android_intent_plus/android_intent.dart';
import 'package:bruno/bruno.dart';
import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:sph_shipper/FandCar/DriverIntroduction.dart';
import 'package:sph_shipper/Order/WaybillDetails/ComplaintService.dart';
import 'package:sph_shipper/Order/WaybillDetails/DriverIDPhoto.dart';
import 'package:sph_shipper/Order/WaybillDetails/ElectronicAgreementView.dart';
import 'package:sph_shipper/Order/WaybillDetails/PictureManagement.dart';
import 'package:sph_shipper/Order/WaybillDetails/TransportProtocolNodes.dart';
import 'package:url_launcher/url_launcher.dart';
import '../../AppConfig/Config.dart';
import '../../AppConfig/LocalStorage.dart';
import '../../AppConfig/RouteAct.dart';
import '../../AppConfig/ShowDialog.dart';
import '../../Message/SingleChatPage.dart';
import '../../SendGoods/DesignatedDriver.dart';
import '../../TabBar/TabbarView.dart';
import '../../http/NoLoadingGetApi.dart';
import '../../http/NoLoadingPostApi.dart';
import '../../http/api.dart';
import '../../http/getapi.dart';
import '../EvaluationPage.dart';
import '../OrderList/RuningOrderList.dart';
import 'CancelWaybillPrompt.dart';
import 'DepositRefundView.dart';
import 'PayTheFreight.dart';
import 'TransportationTrajectory.dart';
import 'UnconfirmedTransportationAgreement.dart';
import 'package:platform/platform.dart';
class WaybillDetails extends StatefulWidget {
  const WaybillDetails({super.key, required this.billId,});

  final String billId;
  @override
  State<WaybillDetails> createState() => _WaybillDetailsState();
}

class _WaybillDetailsState extends State<WaybillDetails> {
  Map dataMap={};
  List orderLogList=[];
  List depositLogList=[];
  List freightLogList=[];
  List serviceLogList=[];
  List protocolLogList=[];
  List trajectoryLogList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getbillDetial();
    getOrderLog();
  }
  _makePhoneCall(String phoneNumber) async {
    if (LocalPlatform().isAndroid) {
      var status = await Permission.phone.status;
      if (status.isGranted) {
        // 权限已被授予
        // callPhone();
        final AndroidIntent intent = AndroidIntent(
          action: 'android.intent.action.CALL',
          data: Uri.encodeFull('tel:$phoneNumber'),
        );
        await intent.launch();
      } else if (status.isDenied) {
        // 权限被拒绝，但用户可以再次授权
        showCallPhoneFirstDialog(context);
        status = await Permission.phone.request();
        if (status.isGranted) {
          // 用户同意了权限
          // callPhone();
          final AndroidIntent intent = AndroidIntent(
            action: 'android.intent.action.CALL',
            data: Uri.encodeFull('tel:$phoneNumber'),
          );
          await intent.launch();
        } else {
          showCallPhoneDialog(context);
          // 用户拒绝权限，无法发起电话
          // 可以在此处展示信息提示用户需要权限
        }
      } else if (status.isPermanentlyDenied) {
        // 权限被永久拒绝，需要用户手动开启权限
        showCallPhoneDialog(context);
      }

    }else{
      final url =Uri.parse('tel:$phoneNumber');
      if (await canLaunchUrl(url)) {
        await launchUrl(url);
      } else {
        throw '无法拨打电话：$url';
      }
    }
  }
  void _copyToClipboard(String copyNumber) {
    Clipboard.setData(ClipboardData(text: copyNumber));
    BrnToast.show('复制成功', context);

  }

  //获取详情
  Future<void> getbillDetial() async {
    NoLoadinggetApiManager.getData(
      context,
      'api/waybill/shipper/waybill/details',
      {
        "waybillId": widget.billId,
      },
          (responseData) {
        setState(() {
          dataMap=responseData['data'];

        });
      },
    );

  }
  Future<void> refuseAction(int refuseStatus) async {
    ApiManager.postData(
      context,
      'api/waybill/waybill/common/refuseWaybill',
      {
        "waybillId":dataMap['waybillId'],
        "refuseStatus":refuseStatus,
      },
          (responseData) {
        setState(() {
          BrnToast.show("操作成功", context);
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(
              builder: (context) => TabbarView(pateIndex: 2,),
              fullscreenDialog: true,),
          );

        });
      },
    );
  }
//获取运单节点
  Future<void> getOrderLog() async {
    NoLoadinggetApiManager.getData(
      context, // 上下文对象，用于显示提示信息等
      'api/waybill/log/page', // 您的API端点
      {"waybillId": widget.billId,}, // 查询参数，如果没有可以传递null
          (responseData)  {
        setState(() {
          orderLogList=responseData['data']['records'];
        });
      },
    );
  }
  Future<void> cancelAction(String waybillId,int cancelStatus) async {
    ApiManager.postData(
      context,
      'api/waybill/waybill/common/cancelWaybill',
      {
        "waybillId":waybillId,
        "cancelStatus":cancelStatus,
      },
          (responseData) {
        setState(() {
          BrnToast.show("操作成功", context);
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(
              builder: (context) => TabbarView(pateIndex: 2,),
              fullscreenDialog: true,),
          );

        });
      },
    );

  }
  //同意/拒绝取消运单
  Future<void> cancelComAction(int sureStatus) async {
    ApiManager.postData(
      context,
      'api/waybill/shipper/waybill/cancel',
      {
        "waybillId":widget.billId,
      },
          (responseData) {
        setState(() {
          BrnToast.show("操作成功", context);
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => TabbarView(pateIndex: 2,),fullscreenDialog: true,),
          );

        });
      },
    );

  }
  //确认收货
  void SureOrderAction()async{

    showDialog(
      barrierDismissible: false,
      context: context,
      builder: (BuildContext context) {
        return BrnDialog(
          titleText: "请确认已完成运输再进行确认收货",
          actionsWidget: [
            TextButton(
              onPressed: () {
                Navigator.pop(context);
              },
              child: Text("取消",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
            ),
            TextButton(
              onPressed: () {
                ApiManager.postData(
                  context,
                  'api/waybill/shipper/waybill/confirmDelivery',
                  {
                    "waybillId": widget.billId,
                  },
                      (responseData) {
                    setState(() {
                      BrnToast.show("已确认收货", context,
                        duration: BrnDuration.short,
                      );
                      Navigator.pushReplacement(
                        context,
                        MaterialPageRoute(
                          builder: (context) => TabbarView(pateIndex: 2,),
                          fullscreenDialog: true,),
                      );
                    });
                  },
                );
              },
              child: Text("确定",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
            ),
          ],
        );
      },
    );

  }
  Future<void> getDrvUserPhoto() async {
    NoLoadinggetApiManager.getData(
      context,
      'api/auth/driver/user/getDocumentById',
      {
        "id": dataMap['driverId'],
      },
          (responseData) {
        setState(() {
          Navigator.push( context, FadeRoute(page:DriverIDPhoto(dataMap:responseData['data'],
          )));
        });
      },
    );
  }
  //0获取订金取向  1获取运费去向 2技术服务费 3电子协议费 4轨迹校验费 5保险费
  Future<void> getMoneyList(int moneyType) async {

  }
  //获取电子协议列表
  Future<void> getContractLogList() async {

  }
  //获取IM的uid
  void getUid(String waybillId) async {

  }
  void choosePageAct(){
    NoLoadinggetApiManager.getData(
      context,
      'api/waybill/shipper/waybill/details',
      {
        "waybillId": widget.billId,
      },
          (responseData) {
        setState(() {
          dataMap=responseData['data'];
          if(dataMap['contractStatus']==0||dataMap['contractStatus']==2){
            Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
            )));
          }else{
            Navigator.push( context, FadeRoute(page:TransportProtocolNodes(waybillId: dataMap['id'],
            )));
          }
        });
      },
    );
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    return Scaffold(

      appBar: AppBar(
        leading: IconButton(icon: Icon(Icons.arrow_back_ios,color: Colors.black,),onPressed: (){Navigator.pop(context);},),
        title: Text("运单详情",style: TextStyle(fontWeight: FontWeight.w300,fontSize: 16.sp),),
        centerTitle: true,
        backgroundColor: Color.fromRGBO(251,236,228,1),
        // actions: [
        //   GestureDetector(
        //     child: Text("投诉"),
        //     onTap: (){
        //       Navigator.push( context, FadeRoute(page:ComplaintService()));
        //     },
        //   ),
        //   Badge(label: Text("1"),),
        // ],
      ),
      body: dataMap.isEmpty? Center(
        child:
        LoadingAnimationWidget.prograssiveDots(color: MyColors.themeColor, size: 50),
      ):
      Container(
        decoration: BoxDecoration(
          gradient: LinearGradient(
            begin: Alignment.topCenter,
            end: Alignment.bottomCenter,
            colors: [Color.fromRGBO(251,236,228,1),MyColors.backgreyColor, MyColors.backgreyColor],
          ),
        ),
        child: Column(
          children: [
            Expanded(child: ListView(
              children: [
                Container(
                  padding: EdgeInsets.only(left: 23.w,right: 45.w),
                  child:  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      GestureDetector( 
                        child: Row(
                          children: [
                            if(dataMap['cancelStatus']==1)
                              Text("已取消",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==1&&dataMap['deliveryStatus']==0&&dataMap['cancelStatus']!=1)
                              Text("待确认收货",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['deliveryStatus']==1&&dataMap['cancelStatus']!=1)
                              Text("已完成",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if((dataMap['contractStatus']==0)&&dataMap['cancelStatus']==0 &&dataMap['cancelStatus']!=1&&dataMap['deliveryStatus']!=1)
                              Text(dataMap['contractMode']=="DRIVER"?"抢单待选用":"指派待确认",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            if(dataMap['contractStatus']==2&&dataMap['cancelStatus']!=1&&dataMap['deliveryStatus']!=1)
                              Text(dataMap['contractMode']=="DRIVER"?"货主待确认":"司机待确认",style: TextStyle(color: MyColors.themeColor,fontSize: 28.sp,fontWeight: FontWeight.w600),),
                            Icon(Icons.arrow_forward_ios,color: MyColors.themeColor,size: 20,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context, builder: (BuildContext context) {
                            return Container(
                              padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,bottom: 40.h),
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.all(Radius.circular(10))),
                              child: Column(
                                children: [
                                  Row(
                                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                    children: [
                                      SizedBox(width: 30.w,),
                                      Text("运单记录",style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                                      IconButton(onPressed: (){
                                        Navigator.pop(context);
                                      }, icon: Icon(Icons.close,color: MyColors.textColor,size: 30,)),
                                    ],
                                  ),
                                  Divider(height: 16.h,color: MyColors.backgreyColor,),
                                  Container(
                                    height:280.h,
                                    child: ListView.builder(
                                      itemCount: orderLogList.length,
                                    itemBuilder: (context, index) {
                                      return Column(
                                        children: [
                                        Row(
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: [
                                          SizedBox(width: 18.w,),
                                          Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),
                                          SizedBox(width: 8.w,),
                                          Column(
                                            crossAxisAlignment: CrossAxisAlignment.start,
                                            mainAxisAlignment: MainAxisAlignment.start,
                                            children: [
                                              Text(orderLogList[index]['description'],style: TextStyle(color: Colors.black),),
                                              Text(orderLogList[index]['createTime'],style: TextStyle(color: MyColors.authTipColor,fontSize: 12.sp),),

                                            ],
                                          )
                                        ],
                                      ),
                                          SizedBox(height: 10.h,),
                                        ],
                                      );
                                       }
                                    ),
                                  ),
                                ],
                              ),
                            );
                          });
                        },
                      ),
                      Image.asset("lib/Images/OrderList/运单详情待确认收货icon.png",width: 50.w,height: 50.h,),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w),
                  padding: EdgeInsets.only(left: 10.w,top: 5.h,right: 10.w,bottom: 5.h),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [

                      if(dataMap['depositType']!=-1)
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(

                              children: [
                                BrnTagCustom.buildBorderTag(
                                  tagText: '订金',
                                  textColor: MyColors.themeColor,
                                  borderColor: MyColors.themeColor,
                                  borderWidth: 1,
                                  fontSize: 10.sp,
                                  textPadding: EdgeInsets.only(left: 4.w,right: 4.w),
                                ),
                                SizedBox(width: 4.w,),
                                Container(
                                  width:screenSize.width-100.w,
                                  child:dataMap['depositStatus']==0?Text("¥${(dataMap['deposit']).toString()}待司机支付",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  dataMap['depositStatus']==1? Text("¥${(dataMap['deposit']).toString()}平台监管中",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  dataMap['depositStatus']==2? Text("¥${(dataMap['deposit']).toString()}已退还司机",style: TextStyle(color: Colors.black,fontSize: 12.sp),):
                                  Text("¥${(dataMap['deposit']).toString()}支付到货主",style: TextStyle(color: Colors.black,fontSize: 12.sp),),

                                )
                              ],
                            ),

                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context,
                              isScrollControlled: true,
                              enableDrag: false,builder: (BuildContext context) {

                          return MoneyGoShowSheet(MoneyType: 1, depositList: depositLogList, freightList: freightLogList, dataMap: dataMap,);
                          });
                        },
                      ),
                      SizedBox(height: 8.h,),
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Row(
                              children: [
                                BrnTagCustom.buildBorderTag(
                                  tagText: '运费',
                                  textColor: MyColors.themeColor,
                                  borderColor: MyColors.themeColor,
                                  borderWidth: 1,
                                  fontSize: 10.sp,
                                  textPadding: EdgeInsets.only(left: 4.w,right: 4.w),
                                ),
                                SizedBox(width: 4.w,),
                                Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                                Text(dataMap['freightStatus']==1?"支付到平台":dataMap['freightStatus']==2?"到司机账户":dataMap['freightStatus']==3?"退回到货主":dataMap['freightStatus']==-1?"线下支付":"待货主支付",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              ],
                            ),

                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          showModalBottomSheet(context: context,
                              isScrollControlled: true,
                              enableDrag: false,builder: (BuildContext context) {
                                return MoneyGoShowSheet(MoneyType: 2,depositList: depositLogList, freightList: freightLogList, dataMap: dataMap,);
                              });
                        },
                      ),
                      SizedBox(height: 8.h,),
                      Text("货运信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      SizedBox(height: 4.h,),
                      Row(
                        children: [
                          Column(
                            children: [
                              Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height:20.h,),
                              Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                              if(dataMap['goodsInfo']['loadPlaceInfo'].length==2)
                                Column(
                                  children: [
                                    Image.asset("lib/Images/OrderList/装货点icon.png",width:20.w ,height:20.h,),
                                    Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                                  ],
                                ),
                              if(dataMap['goodsInfo']['unloadPlaceInfo'].length==2)
                                Column(
                                  children: [
                                    Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height:20.h,),
                                    Image.asset("lib/Images/OrderList/垂直虚线.png",width:18.w ,height:25.h,),
                                  ],
                                ),
                              Image.asset("lib/Images/OrderList/卸货点icon.png",width:20.w ,height:20.h,),
                            ],
                          ),

                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Row(
                                children: [
                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w,
                                      maxWidth:170.w, // 限制文本最大宽度
                                    ),
                                    child: Text(dataMap['goodsInfo']['loadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['loadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),overflow: TextOverflow.ellipsis,),
                                  ),
                                 
                                  SizedBox(width: 8.w,),
                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w,
                                      maxWidth:screenSize.width-240.w, // 限制文本最大宽度
                                    ),
                                    child:Text(dataMap['goodsInfo']['loadDay']+" "+dataMap['goodsInfo']['loadTime']+"点装货",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                  ),


                                ],
                              ),
                              Container(
                                constraints: BoxConstraints(
                                  // minWidth: 60.w,
                                  maxWidth:screenSize.width-80.w, // 限制文本最大宽度
                                ),
                                child:   Text(dataMap['goodsInfo']['loadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                              ),

                             
                              SizedBox(height: 8.h,),
                              if(dataMap['goodsInfo']['loadPlaceInfo'].length==2)
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Container(
                                      constraints: BoxConstraints(
                                        // minWidth: 60.w,
                                        maxWidth:screenSize.width-80.w, // 限制文本最大宽度
                                      ),
                                      child:Text(dataMap['goodsInfo']['loadPlaceInfo'][1]['city']+" "+dataMap['goodsInfo']['loadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),

                                    ),
                                    Container(
                                      constraints: BoxConstraints(
                                        // minWidth: 60.w,
                                        maxWidth:screenSize.width-80.w, // 限制文本最大宽度
                                      ),
                                      child:   Text(dataMap['goodsInfo']['loadPlaceInfo'][1]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                    ),
                                  ],
                                ),

                              if(dataMap['goodsInfo']['unloadPlaceInfo'].length==2)
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Container(
                                      constraints: BoxConstraints(
                                        // minWidth: 60.w,
                                        maxWidth:170.w, // 限制文本最大宽度
                                      ),
                                      child: Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                    ),
                                    Container(
                                      constraints: BoxConstraints(
                                        // minWidth: 60.w,
                                        maxWidth:screenSize.width-80.w, // 限制文本最大宽度
                                      ),
                                      child:  Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                    ),
                                    SizedBox(height: 8.h,),
                                  ],
                                ),
                              Row(
                                children: [
                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w,
                                      maxWidth:170.w, // 限制文本最大宽度
                                    ),
                                    child:  dataMap['goodsInfo']['unloadPlaceInfo'].length==2?
                                    Text(dataMap['goodsInfo']['unloadPlaceInfo'][1]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][1]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),)
                                        :Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['city']+" "+dataMap['goodsInfo']['unloadPlaceInfo'][0]['county'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                  ),


                                  SizedBox(width: 8.w,),
                                  if(dataMap['goodsInfo']['unloadDay']!=null)
                                    Container(
                                      constraints: BoxConstraints(
                                        // minWidth: 60.w,
                                        maxWidth:screenSize.width-240.w, // 限制文本最大宽度
                                      ),
                                      child: Text(dataMap['goodsInfo']['unloadDay']+" "+dataMap['goodsInfo']['unloadTime']+"点卸货",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                    ),

                                ],
                              ),

                                  Container(
                                    constraints: BoxConstraints(
                                      // minWidth: 60.w,
                                      maxWidth:screenSize.width-80.w, // 限制文本最大宽度
                                    ),
                                    child:  dataMap['goodsInfo']['unloadPlaceInfo'].length==2?  Text(dataMap['goodsInfo']['unloadPlaceInfo'][1]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,):
                                    Text(dataMap['goodsInfo']['unloadPlaceInfo'][0]['address'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),overflow: TextOverflow.ellipsis,),
                                  )

                            ],
                          ),
                        ],
                      ),
                      SizedBox(height: 8.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text("全程",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                              // Text( (int.parse(dataMap['distance'])/1000).toStringAsFixed(2) ,style: TextStyle(color: MyColors.themeColor,fontSize: 12.sp),),
                              Text("公里",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            ],
                          ),
                          GestureDetector(
                            child: Text("查看运输轨迹",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            onTap: (){
                              Navigator.push( context, FadeRoute(page:TransportationTrajectory()));
                            },
                          ),
                        ],
                      ),
                      Divider(height: 16.h,color: MyColors.backgreyColor,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Image.asset("lib/Images/OrderList/包裹icon.png",width: 24.w,height: 24.h,),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']!=null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']!=null)
                              Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight'].toString()+"吨"+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume'].toString()+"方",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']==null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']!=null)
                                Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']+"方",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                              if(dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight']!=null&&dataMap['goodsInfo']['cargoInfo'][0]['cargoVolume']==null)
                                Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName']+"  "+dataMap['goodsInfo']['cargoInfo'][0]['cargoWeight'].toString()+"吨"+"  ",style: TextStyle(color: Colors.black,fontSize: 12.sp),),

                            ],
                          ),
                          GestureDetector(
                            child:  Text("货物详情>",style: TextStyle(color: Colors.black,fontSize: 12.sp),),
                            onTap: (){
                              showModalBottomSheet(context: context,
                                  isScrollControlled: true,
                                  enableDrag: false,builder: (BuildContext context) {

                                    return Container(
                                      height: 238.h,
                                      width: MediaQuery.of(context).size.width,
                                      padding: EdgeInsets.only(left: 18.w,right: 18.w,top: 15.h),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.all(Radius.circular(10))),
                                      child: Column(
                                        children: [
                                            Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                SizedBox(width: 30.w,),
                                                Text("货物详情",style: TextStyle(color: Colors.black,fontSize: 16.sp),),
                                                IconButton(onPressed: (){
                                                  Navigator.pop(context);
                                                }, icon: Icon(Icons.close,size: 30,color: Colors.black,)),
                                              ],
                                            ),
                                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                                          Row(
                                            children: [
                                              Text("货物",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                              Text(dataMap['goodsInfo']['cargoInfo'][0]['cargoName'],style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),
                                          SizedBox(height: 15.h,),
                                          Row(
                                            children: [
                                              Text("车辆",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                               Text(dataMap['vehicleInfo']['vehicleLength'].toString()+"米,"+dataMap['vehicleInfo']['vehicleModel'],style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),
                                          SizedBox(height: 15.h,),
                                          Row(
                                            children: [
                                              Text("备注",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                              SizedBox(width: 23.w,),
                                              Text(dataMap['remark']!=null?dataMap['remark']:"",style: TextStyle(color:Colors.black,fontSize: 14.sp),),
                                            ],
                                          ),

                                        ],
                                      ),
                                    );
                                  });
                            },
                          ),

                        ],
                      )
                    ],
                  ),
                ),

                if(dataMap['depositType']!=-1)
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text("订金",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              SizedBox(width: 6.w,),
                              BrnTagCustom(
                                tagText:dataMap['depositType']==0? "可退":"不退还",
                                textColor: Colors.white,
                                fontSize: 9.sp,
                                backgroundColor: Color.fromRGBO(239,160,82,1),
                                textPadding:EdgeInsets.only(left: 4.w,right: 4.w),
                                fontWeight: FontWeight.w600,
                              ),
                            ],
                          ),
                          Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                        ],
                      ),
                      SizedBox(height:10.h ,),

                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("订金",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==1)
                          Row(
                            children: [
                              Text("平台监管账户中",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                              Image.asset("lib/Images/OrderList/平台监管账户中icon.png",width: 17.w,height: 17.h,),
                            ],
                          ),
                          if(dataMap['depositStatus']==3)
                            Text("已支付到货主账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==2)
                            Text("退款成功",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==0)
                            Text("待支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                        ],
                      ),
                    ],
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Text("运费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            ],
                          ),
                          Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                        ],
                      ),
                      SizedBox(height:10.h ,),

                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("运费",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['freightStatus']==1)
                            Row(
                              children: [
                                Text("平台监管账户中",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                                Image.asset("lib/Images/OrderList/平台监管账户中icon.png",width: 17.w,height: 17.h,),
                              ],
                            ),
                          if(dataMap['freightStatus']==2)
                            Text("已支付到司机账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==3)
                            Text("已退回到货主账户",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==0)
                            Text("待支付",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                          if(dataMap['depositStatus']==-1)
                            Text("线下支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                          Text("¥"+(dataMap['freight']).toString(),style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                        ],
                      ),
                      Divider(height: 16.h,color: MyColors.backgreyColor,),
                      GestureDetector(
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            Text("查看运费修改记录",style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.authTipColor,),
                          ],
                        ),
                        onTap: (){
                          NoLoadinggetApiManager.getData(
                            context,
                            "api/waybill/freight/change/page",
                            {'current':'1','size':20,"waybillId":dataMap['id']},
                                (responseData)  {
                              showModalBottomSheet(context: context,
                                  isScrollControlled: true,
                                  builder: (BuildContext context) {
                                    return Container(
                                      height: 300.h,
                                      padding: EdgeInsets.only(top: 10.h,bottom: 20.h,left: 10.w,right: 10.w),
                                      decoration: BoxDecoration(
                                          color: Colors.white,
                                          borderRadius: BorderRadius.all(Radius.circular(10))),
                                      child: Column(
                                        children: [
                                          Row(
                                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                            children: [
                                              SizedBox(width: 20.w,),
                                              Text("修改记录",style: TextStyle(color: MyColors.textColor,fontSize: 16.sp,fontWeight: FontWeight.w600),),
                                              GestureDetector(
                                                child: Icon(Icons.close,color: MyColors.authTipColor,size: 30,),
                                                onTap: (){
                                                  Navigator.pop(context);
                                                },
                                              ),
                                            ],
                                          ),
                                          Divider(height: 16.h,color: MyColors.backgreyColor,),
                                          Container(
                                            height:200.h,
                                            child: ListView.builder(
                                                shrinkWrap:false,
                                                itemCount:responseData['data']['records'].length+1,
                                                itemBuilder: (BuildContext context, int index) {
                                                  return Container(
                                                    child: Column(
                                                      crossAxisAlignment: CrossAxisAlignment.start,
                                                      children: [

                                                        Row(
                                                          children: [
                                                            Icon(Icons.panorama_fisheye,color: MyColors.themeColor,size: 8,),
                                                            SizedBox(width: 15.w,),
                                                            Text(index==0?dataMap['freight']:responseData['data']['records'][index]['freight']+"元/趟",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                                          ],
                                                        ),
                                                        Row(
                                                          children: [
                                                            SizedBox(width: 23.w,),
                                                            Text(index==0?(dataMap['createTime']+"货主发货填写"):(responseData['data']['records'][index]['createTime']+responseData['data']['records'][index]['description']),style: TextStyle(color: MyColors.authTipColor,fontSize: 13.sp),),
                                                          ],
                                                        ),

                                                        SizedBox(height: 8.h,),
                                                      ],
                                                    ),
                                                  );}
                                            ),
                                          )
                                        ],
                                      ),
                                    );
                                  });
                            },
                          );

                        },
                      ),
                    ],
                  ),
                ),
                // Container(
                //   margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                //   padding: EdgeInsets.only(left: 10.w,top:10.h,right:10.w,bottom: 10.h),
                //   decoration: BoxDecoration(
                //       color: Colors.white,
                //       borderRadius: BorderRadius.all(Radius.circular(10))),
                //   child: Column(
                //     children: [
                //       Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Row(
                //             children: [
                //               Text("技术服务费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                //             ],
                //           ),
                //           Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 13.sp),),
                //         ],
                //       ),
                //       SizedBox(height:10.h ,),
                //
                //       Row(
                //         mainAxisAlignment: MainAxisAlignment.spaceBetween,
                //         children: [
                //           Text("技术服务费",style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                //           if(dataMap['depositStatus']==2)
                //             Text("已支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                //           if(dataMap['depositStatus']==0)
                //             Text("待支付",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                //           Text("¥"+(dataMap['deposit']).toString(),style: TextStyle(color:MyColors.textColor,fontSize: 12.sp),),
                //         ],
                //       ),
                //     ],
                //   ),
                // ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:10.h,right:6.w,bottom: 9.h),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [

                            ClipRRect(
                              borderRadius: BorderRadius.circular(10.0), // 设置圆角半径
                              child: Image.network(
                                MyServiceUrl.imgHeader + dataMap['driverInfo']['avatarPath'],
                                width: 36.w,
                                height: 36.h,
                                fit: BoxFit.cover, // 图片填充方式，可以根据需要调整
                              ),
                            ),
                            SizedBox(width: 13.w,),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(dataMap['driverInfo']['realName'],style: TextStyle(color: Colors.black,fontSize: 14.sp)),
                                Text(dataMap['driverInfo']['phoneNum'],style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                              ],
                            ),
                          ],
                        ),
                        Row(
                          children: [
                            GestureDetector(
                              child: Image.asset("lib/Images/OrderList/IMicon.png",width: 24.w,height: 24.h,),
                              onTap: (){
                                getUid(dataMap['waybillId']);
                              },
                            ),
                            SizedBox(width: 8.w,),
                            GestureDetector(
                              child: Image.asset("lib/Images/OrderList/电话联系icon.png",width: 24.w,height: 24.h,),
                              onTap: (){
                                _makePhoneCall(dataMap['driverInfo']['phoneNum']);
                              },
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){
                    Navigator.push( context, FadeRoute(page:DriverIntroduction(DrvId: dataMap['driverId'],)));
                  },
                ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:9.h,bottom: 7.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Text("司机证件",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            SizedBox(height: 4.h,),
                            Text("身份证、驾驶证、行驶证",style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                          ],
                        ),
                        Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                      ],
                    ),

                  ),
                  onTap: (){
                   getDrvUserPhoto();
                  },
                ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("货物运输协议",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        Row(
                          children: [
                            Text(dataMap['contractStatus']==0||dataMap['contractStatus']==2?"待签署":"已签",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: () async {
                    choosePageAct();

                  }
                ),
                if(dataMap['invoiceType']==1)
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text("电子协议",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                        Row(
                          children: [
                            Text("查看和下载",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){
                    getContractLogList();
                  },
                ),
                GestureDetector(
                  child:  Container(
                    margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                    padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 12.h,right: 5.w),
                    decoration: BoxDecoration(
                        color: Colors.white,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Row(
                          children: [
                            Text("图片",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                            Text("（装卸图片、回单）",style: TextStyle(color: MyColors.textColor),),
                          ],
                        ),

                        Row(
                          children: [
                            Text("查看",style: TextStyle(color: MyColors.textColor,fontSize: 12.sp),),
                            Icon(Icons.arrow_forward_ios,size: 14,color: MyColors.hintColor,),
                          ],
                        )
                      ],
                    ),
                  ),
                  onTap: (){
                    Navigator.push( context, FadeRoute(page:PictureManagement(type: 1, dataMap: dataMap,)));
                  },
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 10.w,top:10.h,bottom: 10.h,right: 10.w),
                  decoration: BoxDecoration(
                      color: Color.fromRGBO(251, 236, 228, 1),
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Text("为保障订单顺利成交及跟车人员（如有）人身安全，请您在实际装货前务必核实并承诺实际货物信息、司机、车辆与订单展示一致。如不一致，您应当拒绝交易，否则后果自负！",
                  style: TextStyle(color: Colors.black,fontSize: 11.sp),),
                ),
                Container(
                  margin: EdgeInsets.only(left: 10.w,right: 10.w,top:8.h),
                  padding: EdgeInsets.only(left: 12.w,top:12.h,bottom: 8.h,right: 9.w),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text("其他信息",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                      SizedBox(height: 8.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("运单编号",style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                          Row(
                            children: [
                              Text(dataMap['id'],style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                              SizedBox(width: 8.w,),
                              GestureDetector(
                                child:  Text("复制",style: TextStyle(fontSize: 12.sp,color: MyColors.themeColor),),
                                onTap: (){
                                  _copyToClipboard(dataMap['waybillId']);
                                },
                              ),
                            ],
                          )
                        ],
                      ),
                      SizedBox(height: 8.h,),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text("下单时间",style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                          Text(dataMap['createTime'],style: TextStyle(fontSize: 12.sp,color: MyColors.textColor),),
                        ],
                      ),
                    ],
                  ),
                ),
      ],
            ),
            ),
            if(dataMap['cancelStatus']!=1)
            Container(
              padding: EdgeInsets.only(left: 10.w,top: 10.h,right: 10.w,bottom: 35.h),
              decoration: BoxDecoration(
                  color: Colors.white,
                  borderRadius: BorderRadius.all(Radius.circular(10))),
              child:Row(
                mainAxisAlignment: MainAxisAlignment.end,
                children: [
                  // if(dataMap['deliveryStatus']!=1&&dataMap['cancelStatus']!=2)
                  //   GestureDetector(
                  //     child:  Container(
                  //         width: 75.w,
                  //         height: 25.h,
                  //         decoration: BoxDecoration(
                  //           color: Colors.white,
                  //           borderRadius: BorderRadius.circular(30.0),
                  //           border: Border.all(
                  //             color: MyColors.themeColor,
                  //             width: 1.0,
                  //           ),
                  //         ),
                  //         child: Center(child: Text("取消运单",style: TextStyle(fontSize: 13.sp,color:  MyColors.themeColor,fontWeight: FontWeight.w600),),)
                  //     ),
                  //     onTap: ()  {
                  //       BrnDialogManager.showConfirmDialog(context,
                  //         message:"确认取消运单吗？",
                  //         cancel: '',
                  //         cancelWidget: GestureDetector(
                  //           child: Center(
                  //             child:  Text("我再想想",style: TextStyle(color: Colors.black),),
                  //           ),
                  //           onTap: (){
                  //             Navigator.pop(context);
                  //           },
                  //         ),
                  //         conformWidget:GestureDetector(
                  //           child:  Center(
                  //             child:  Text("确定取消",style: TextStyle(color: MyColors.themeColor),),
                  //           ),
                  //           onTap: (){
                  //             Navigator.pop(context);
                  //             cancelComAction(1);
                  //           },
                  //         ),
                  //         confirm: '', );
                  //     },
                  //   ),

                  if(dataMap['contractEffectiveness']==1&&dataMap['depositType']!=-1&&dataMap['depositStatus']==1&&dataMap['deliveryStatus']==0&&dataMap['cancelStatus']!=1)
                    Row(
                      children: [
                        SizedBox(width: 8.w,),
                        GestureDetector(
                          child:  Container(
                              width: 75.w,
                              height: 25.h,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(30.0),
                                border: Border.all(
                                  color: MyColors.themeColor,
                                  width: 1.0,
                                ),
                              ),
                              child: Center(child: Text("退还订金",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                          ),
                          onTap: ()  {
                            BrnDialogManager.showConfirmDialog(context,
                              title:"确定要将订金退还给司机吗？",

                              // barrierDismissible:false,
                              cancel: '',
                              cancelWidget: GestureDetector(
                                child: Center(
                                  child:  Text("我再想想",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                                ),
                                onTap: (){
                                  Navigator.pop(context);
                                },
                              ),
                              conformWidget:GestureDetector(
                                child:  Center(
                                  child:  Text("确定退还",style: TextStyle(color: MyColors.themeColor,fontSize: 14.sp),),
                                ),
                                onTap: (){
                                  getApiManager.getData(
                                    context,
                                    'api/pay/deposit/bill/refundDeposit',
                                    {
                                      "waybillId":dataMap['id'],
                                    },
                                        (responseData) {
                                      setState(() {
                                        Navigator.pop(context);
                                        BrnToast.show("操作成功", context);
                                        getbillDetial();
                                      });
                                    },
                                  );
                                },
                              ),
                              confirm: '', );
                          },
                        ),
                      ],
                    ),
                  if((dataMap['contractStatus']==0||dataMap['contractStatus']==2)&&dataMap['contractMode']=="DRIVER"&&dataMap['cancelStatus']!=1)
                    Row(
                      children: [
                        SizedBox(width: 8.w,),
                        GestureDetector(
                          child:  Container(
                              width: 75.w,
                              height: 25.h,
                              decoration: BoxDecoration(
                                color:Colors.white,
                                borderRadius: BorderRadius.circular(30.0),
                                border: Border.all(
                                  color: MyColors.themeColor,
                                  width: 1.0,
                                ),
                              ),
                              child: Center(child: Text("确认协议",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                          ),
                          onTap: ()  {
                            Navigator.push( context, FadeRoute(page:UnconfirmedTransportationAgreement(wayBillId: dataMap['id'], Type: 1,
                            )));
                          },
                        ),
                      ],
                    ),
                  if(dataMap['contractEffectiveness']==1&&dataMap['deliveryStatus']==0&&dataMap['freightStatus']==0&&dataMap['cancelStatus']!=1)
                    Row(
                      children: [
                        SizedBox(width: 8.w,),
                        GestureDetector(
                          child:  Container(
                              width: 75.w,
                              height: 25.h,
                              decoration: BoxDecoration(
                                color:Colors.white,
                                borderRadius: BorderRadius.circular(30.0),
                                border: Border.all(
                                  color: MyColors.themeColor,
                                  width: 1.0,
                                ),
                              ),
                              child: Center(child: Text("确认收货",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                          ),
                          onTap: ()  {
                            SureOrderAction();
                          },
                        ),

                      ],
                    ),
                  if(dataMap['contractEffectiveness']==1&&dataMap['freightStatus']==0&&dataMap['cancelStatus']!=1)
                    Row(
                      children: [
                        SizedBox(width: 8.w,),
                        GestureDetector(
                          child:  Container(
                              width: 75.w,
                              height: 25.h,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(30.0),
                                border: Border.all(
                                  color: MyColors.themeColor,
                                  width: 1.0,
                                ),
                              ),
                              child: Center(child: Text("支付运费",style: TextStyle(fontSize: 13.sp,color: MyColors.themeColor,fontWeight: FontWeight.w600),),)
                          ),
                          onTap: () async{
                            showModalBottomSheet(context: context,
                                builder: (BuildContext context) {
                                  return Container(
                                    height: 200.h,
                                    padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 10.h),
                                    decoration: BoxDecoration(
                                        color: Colors.white,
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(10))),
                                    child: Column(
                                      children: [
                                        Row(
                                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                          children: [
                                            SizedBox(width: 15.w,),
                                            Text("支付方式",style: TextStyle(color: Colors.black,fontSize: 14.sp,fontWeight: FontWeight.w600),),
                                            GestureDetector(
                                              child: Icon(Icons.close,color: MyColors.textColor,size: 30,),
                                              onTap: (){
                                                Navigator.pop(context);
                                              },
                                            ),
                                          ],
                                        ),
                                        SizedBox(height: 10.h,),
                                        GestureDetector(
                                          child:  Container(
                                            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,bottom: 8.h),
                                            decoration: BoxDecoration(
                                                color: Color.fromRGBO(251, 236, 228, 0.5),
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(10))),
                                            child: Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                Row(
                                                  children: [
                                                    Image.asset("lib/Images/OrderList/直接支付icon.png",width: 30.w,height: 30.h,),
                                                    SizedBox(width: 4.w,),
                                                    Text("直接支付",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                                  ],
                                                ),
                                                Text("超过90%的货主选择直接支付运费",style: TextStyle(color: MyColors.hintColor,fontSize: 12.sp),),
                                              ],
                                            ),
                                          ),
                                          onTap: (){
                                            NoLoadingApiManager.postData(
                                              context,
                                              "api/pay/wallet/shipper/addFreightBill",
                                              {
                                                "productId":dataMap['id'],
                                              },
                                                  (responseData)  {
                                                Navigator.push( context, FadeRoute(page:PayTheFreight(dataMap:dataMap, payType: 1, payId: responseData['data'],)));
                                              },
                                            );
                                          },
                                        ),
                                        SizedBox(height: 10.h,),
                                        GestureDetector(
                                          child:  Container(
                                            padding: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h,bottom: 8.h),
                                            decoration: BoxDecoration(
                                                color: Color.fromRGBO(251, 236, 228, 0.5),
                                                borderRadius: BorderRadius.all(
                                                    Radius.circular(10))),
                                            child: Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                Row(
                                                  children: [
                                                    Image.asset("lib/Images/OrderList/线下支付icon.png",width: 30.w,height: 30.h,),
                                                    SizedBox(width: 4.w,),
                                                    Text("线下支付",style: TextStyle(color: MyColors.textColor,fontSize: 14.sp),),
                                                  ],
                                                ),
                                              ],
                                            ),
                                          ),
                                          onTap: (){
                                            getApiManager.getData(
                                              context,
                                              "api/waybill/shipper/waybill/payFreightOffline",
                                              {"waybillId":dataMap['id'],},
                                                  (responseData)  {
                                                BrnToast.show("已选择线下支付", context);
                                              },
                                            );
                                          },
                                        ),

                                      ],
                                    ),
                                  );});

                          },
                        ),

                      ],
                    ),
                  if(dataMap['shipperEvaluateStatus']==0&&dataMap['deliveryStatus']==1&&dataMap['cancelStatus']!=1)
                    Row(
                      children: [
                        SizedBox(width: 8.w,),
                        GestureDetector(
                          child:  Container(
                              width: 75.w,
                              height: 25.h,
                              decoration: BoxDecoration(
                                color: MyColors.themeColor,
                                borderRadius: BorderRadius.circular(30.0),
                                border: Border.all(
                                  color: MyColors.themeColor,
                                  width: 1.0,
                                ),
                              ),
                              child: Center(child: Text("评价司机",style: TextStyle(fontSize: 13.sp,color: Colors.white,fontWeight: FontWeight.w600),),)
                          ),
                          onTap: ()  {
                            Navigator.push( context, FadeRoute(page:EvaluationPage(dataMap: dataMap,)));
                          },
                        ),


                      ],
                    ),
                ],
              ),),


          ],
        ),

      ),
    );
  }
}

class MoneyGoShowSheet extends StatefulWidget {
  const MoneyGoShowSheet({super.key, required this.MoneyType, required this.depositList, required this.freightList, required this.dataMap});
  final int MoneyType;
  final List depositList;
  final List freightList;
  final Map dataMap;
  @override
  State<MoneyGoShowSheet> createState() => _MoneyGoShowSheetState();
}

class _MoneyGoShowSheetState extends State<MoneyGoShowSheet> {
  int checkType=-1;
  List depositList=[];
  List freightList=[];
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    checkType =widget.MoneyType;
    getDepositAct();
    getFreightAct();
  }
  void getDepositAct(){
    NoLoadinggetApiManager.getData(
      context,
      "api/pay/deposit/log/page",
      {'waybillId':widget.dataMap['id']},
          (responseData)  {
        setState(() {
          depositList=responseData['data']['records'];
        });

      },
    );
  }
  void getFreightAct(){
    NoLoadinggetApiManager.getData(
      context,
      "api/pay/freight/log/page",
      {'waybillId':widget.dataMap['id']},
          (responseData)  {
        setState(() {
          freightList=responseData['data']['records'];
        });

      },
    );
  }
  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;

    return Container(
        height: 500.h,
      decoration: BoxDecoration(
          color: MyColors.backgreyColor,
          borderRadius: BorderRadius.all(Radius.circular(10))),
      child: Column(
        children: [
          Container(
            padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            child:  Row(

              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                SizedBox(width: 30.w,),
                Text("钱款去向",style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                IconButton(onPressed: (){
                  Navigator.pop(context);
                }, icon: Icon(Icons.close,color: MyColors.textColor,size: 30,)),
              ],
            ),
          ),

    Container(
    padding: EdgeInsets.only(left: 12.w,top: 15.h,right: 12.w,),
    decoration: BoxDecoration(
    color: Colors.white,
    borderRadius: BorderRadius.all(Radius.circular(10))),
      child:Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          SizedBox(),
          GestureDetector(
            child: Column(
              children: [
                Text("订金",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                Container(width: 20.w,height: 2.h,color: checkType==1?MyColors.themeColor:Colors.white,),
              ],
            ),
            onTap: (){
              setState(() {
                checkType=1;
              });
            },
          ),
          GestureDetector(
            child: Column(
              children: [
                Text("运费",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                Container(width: 20.w,height: 2.h,color: checkType==2?MyColors.themeColor:Colors.white,),
              ],
            ),
            onTap: (){
              setState(() {
                checkType=2;
              });
            },
          ),
          SizedBox(),
        ],
      ),
    ),
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            child: Column(
              children: [
            Container(
              height: 40.h,
            decoration: BoxDecoration(
                borderRadius: BorderRadius.only(topLeft: Radius.circular(10),topRight: Radius.circular(10)),
            gradient: LinearGradient(
              begin: Alignment.topLeft,
              end: Alignment.bottomRight,
              colors: [Color.fromRGBO(253,252,248,1), Color.fromRGBO(251,236,228,1)],
            ),
          ),
              child:
              checkType==1?
              Row(
                children: [
                  SizedBox(width: 16.w,),
                  Icon(Icons.access_time_filled,color: MyColors.themeColor,),
                  SizedBox(width: 6.w,),
                  if(widget.dataMap['depositStatus']==1)
                    Text("支付到平台",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['depositStatus']==2)
                    Text("到货主账户",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['depositStatus']==3)
                    Text("已退回",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                ],
              ): Row(
                children: [
                  SizedBox(width: 16.w,),
                  Icon(Icons.access_time_filled,color: MyColors.themeColor,),
                  SizedBox(width: 6.w,),
                  if(widget.dataMap['freightStatus']==1)
                    Text("支付到平台",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==2)
                    Text("到司机账户",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==0)
                    Text("待支付",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                  if(widget.dataMap['freightStatus']==-1)
                    Text("线下支付",style: TextStyle(color: MyColors.themeColor,fontSize: 16.sp),),
                ],
              ),
            ),
                SizedBox(height: 19.h,),
                checkType==1?
                Row(
                  children: [
                    SizedBox(width: 13.w,),
                    Text("订金：¥",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    Text((widget.dataMap['deposit']).toString(),style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                  ],
                ):
                Row(
                  children: [
                    SizedBox(width: 13.w,),
                    Text("运费：¥",style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                    Text((widget.dataMap['freight']).toString(),style: TextStyle(color: Colors.black,fontSize: 18.sp),),
                  ],
                ),
              SizedBox(height: 18.h,),
              ],
            ),
          ),
          checkType==1?
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(top: 22.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            height:screenSize.width-30.h,
            child: ListView.builder(
                itemCount: depositList.length,
                itemBuilder: (context, index) {
                  return Column(
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(width: 18.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              SizedBox(height: 4.h,),
                              Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),
                            ],
                          ),
                          SizedBox(width: 8.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text(depositList[index]['description'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              Text(depositList[index]['createTime'],style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),

                            ],
                          ),
                        ],
                      ),
                      SizedBox(height: 10.h,),
                    ],
                  );
                }
            ),
          ):
          Container(
            margin: EdgeInsets.only(left: 10.w,right: 10.w,top: 8.h),
            padding: EdgeInsets.only(top: 22.h),
            decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(Radius.circular(10))),
            height:screenSize.width-30.h,
            child: ListView.builder(
                itemCount: widget.freightList.length,
                itemBuilder: (context, index) {
                  return  Column(
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          SizedBox(width: 18.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              SizedBox(height: 4,),
                              Icon(Icons.circle,color: index==0?MyColors.themeColor:MyColors.hintColor,size: 12,),

                            ],
                          ),
                          SizedBox(width: 8.w,),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              Text(freightList[index]['description'],style: TextStyle(color: Colors.black,fontSize: 14.sp),),
                              Text(freightList[index]['createTime'],style: TextStyle(color: MyColors.textColor,fontSize: 13.sp),),
                            ],
                          )
                        ],
                      ),
                      SizedBox(height: 10.h,),
                    ],
                  );
                }
            ),
          ),
        ],
      ),
    );
  }
}


